<template>
  <ConfigProvider :locale="getAntdLocale">
    <AppProvider>
      <RouterView />
    </AppProvider>
  </ConfigProvider>
</template>

<script lang="ts" setup>
  import { ConfigProvider } from 'ant-design-vue';
  import { AppProvider } from '/@/components/Application';
  import { useTitle } from '/@/hooks/web/useTitle';
  import { useLocale } from '/@/locales/useLocale';
  import { useUserStore } from '/@/store/modules/user';

  import 'dayjs/locale/zh-cn';
  // support Multi-language
  const { getAntdLocale } = useLocale();

  // Listening to page changes and dynamically changing site titles
  useTitle();

  const userStore = useUserStore();
  if (window.localStorage.getItem('serverInfo')) {
    let serverInfo = window.localStorage.getItem('serverInfo');
    if (serverInfo == null) {
      serverInfo = '{}';
    }
    userStore.serverInfo = JSON.parse(serverInfo);
  }

  window.addEventListener('beforeunload', () => {
    window.localStorage.setItem('serverInfo', JSON.stringify(userStore.serverInfo));
  });
</script>
